package com.avic.rong.userOrder.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.avic.rong.BaseActivity;
import com.avic.rong.R;
import com.avic.rong.activity.login.LoginActivity;
import com.avic.rong.adapter.MineLikeAdapter;
import com.avic.rong.payUtil.JavaPayUtil;
import com.avic.rong.payUtil.PayVo;
import com.avic.rong.userOrder.adapter.PayWayAdapter;
import com.avic.rong.userOrder.api.CaiLikeApi;
import com.avic.rong.userOrder.api.PayConsequenceApi;
import com.avic.rong.userOrder.api.PayConsequencePXApi;
import com.avic.rong.userOrder.api.PaySubmitApi;
import com.avic.rong.userOrder.api.PaySubmitPXApi;
import com.avic.rong.userOrder.api.ToPayApi;
import com.avic.rong.userOrder.api.ToPayPXApi;
import com.avic.rong.userOrder.bean.CaiLikeBean;
import com.avic.rong.userOrder.bean.PayWayBean;
import com.avic.rong.userOrder.bean.ResultQueryBean;
import com.avic.rong.userOrder.bean.ResultQueryPXBean;
import com.avic.rong.userOrder.bean.ResultQueryPXSmatBean;
import com.avic.rong.userOrder.bean.ResultQuerySmartBean;
import com.avic.rong.utils.ConstantsUtils;
import com.avic.rong.utils.DateUtils;
import com.avic.rong.utils.DialogCustom;
import com.avic.rong.utils.MoneyShowUtils;
import com.avic.rong.utils.NetResponseListener;
import com.avic.rong.utils.SharedPreferencesUtil;
import com.avic.rong.utils.SmartHttp;
import com.avic.rong.utils.ToastTools;
import com.avic.rong.wedgit.loadingLayout.LoadingLayout;
import com.example.minato.minastore.BaseResultEntity;
import com.example.minato.minastore.http.HttpManager;
import com.example.minato.minastore.listener.HttpOnNextListener;
import com.example.minato.minastore.utils.AppUtils;
import com.example.minato.minastore.utils.CircleProgressDialog;
import com.google.gson.Gson;

import org.json.JSONObject;

import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;


public class PaySucceedActivity extends BaseActivity {


    @BindView(R.id.ll_root)
    LinearLayout llRoot;
    @BindView(R.id.iv_pic)
    ImageView ivPic;

    @BindView(R.id.v_line)
    View vLine;
    @BindView(R.id.tv_order_tel)
    TextView tvOrderTel;
    @BindView(R.id.tv_order_money)
    TextView tvOrderMoney;
    @BindView(R.id.tv_under_order_time)
    TextView tvUnderOrderTime;
    @BindView(R.id.tv_order_way)
    TextView tvOrderWay;
    @BindView(R.id.tv_look_order)
    TextView tvLookOrder;
    @BindView(R.id.recycler_list)
    RecyclerView recyclerList;
    @BindView(R.id.loading_layout)
    LoadingLayout loading_layout;
    @BindView(R.id.tv_again_pay)
    TextView tvAgainPay;
    @BindView(R.id.tv_look_order_gray)
    TextView tvLookOrderGray;
    @BindView(R.id.ll_pay_failed)
    LinearLayout llPayFailed;
    @BindView(R.id.ll_list)
    LinearLayout llList;
    @BindView(R.id.tv_paystate_title)
    TextView tvPaystateTitle;
    private String order_id;
    private String order_sn;
    private String pay_state = null;
    private int order_type = -1;
    private ArrayList<CaiLikeBean> listData = new ArrayList<>();
    private MineLikeAdapter mineLikeAdapter;
    private List<PayWayBean.PaymentListBean> paymentList = new ArrayList<>();
    private PayWayAdapter payWayAdapter;
    private PopupWindow popupWindow;
    private int payId = -1;
    private boolean isAgreement = true;//勾选用户协议

    private JavaPayUtil javaPayUtil;
    public static String ORDER_ID = "order_id";
    public static String ORDER_SN = "order_sn";
    private int COMMENT_FORCODE = 6;



    @Override
    protected int getContentViewId() {
        return R.layout.activity_pay_succeed;
    }

    @Override
    protected void initView() {

        if (!TextUtils.isEmpty(getIntent().getStringExtra("order_id")) || !TextUtils.isEmpty(getIntent().getStringExtra("order_sn"))) {
            order_id = getIntent().getStringExtra("order_id");
            order_sn = getIntent().getStringExtra("order_sn");

        } else {
            finish();
        }
        if (!TextUtils.isEmpty(getIntent().getStringExtra("pay_state"))) {
            pay_state = getIntent().getStringExtra("pay_state");
        }

        if (getIntent().getIntExtra("order_type", -1) == -1) {
            finish();
        } else {
            order_type = getIntent().getIntExtra("order_type", -1);
        }
        //禁止recyclerview滑动
        recyclerList.setNestedScrollingEnabled(false);
        recyclerList.setLayoutManager(new GridLayoutManager(this, 2));

        mineLikeAdapter = new MineLikeAdapter(this, listData);
        recyclerList.setAdapter(mineLikeAdapter);
        if (order_type != 5) {
            //查询支付结果
            resultQuery();
        } else {
            //培训查询支付结果
            resultQueryPX();
        }

        //猜你需要
        caiLike();


    }


    PayConsequencePXApi payConsequencePXApi;

    private void resultQueryPX() {
        if (SharedPreferencesUtil.isLogin()) {
            Map<String, String> map = new HashMap<>();
            map.put("orderNumber", order_sn);
            map.put("token", getSharedPreferencesUtil().getLogintoken());
          /*  payConsequencePXApi = new PayConsequencePXApi(PaySucceedActivity.this, simpleOnNextListenerPX);
            payConsequencePXApi.setCache(false);
            payConsequencePXApi.setMap(map);
            HttpManager.getInstance().doHttpDeal(payConsequencePXApi);*/
            loading_layout.setStatus(LoadingLayout.LOADING);
            SmartHttp.postHttpForm(AppUtils.BASE_URL + "pay/train/payConsequence", map, new NetResponseListener() {
                @Override
                public void sucListener(JSONObject response) {
                    Gson gson = new Gson();
                    ResultQueryPXSmatBean resultQueryPXSmatBean = gson.fromJson(response.toString(), ResultQueryPXSmatBean.class);
                    if (!resultQueryPXSmatBean.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                        ToastTools.showToast(PaySucceedActivity.this, resultQueryPXSmatBean.getMsg());
                        return;
                    }
                    loading_layout.setStatus(LoadingLayout.SUCCESS);

                    if (resultQueryPXSmatBean.getData() != null) {

                        ResultQueryPXSmatBean.DataBean data = resultQueryPXSmatBean.getData();
                        ResultQueryPXSmatBean.DataBean.OrderBean order = data.getOrder();
                        if (!TextUtils.isEmpty(pay_state) && pay_state.equals("1")) {
                            tvTitle.setText("支付成功");
                            tvPaystateTitle.setText("订单支付成功，您可查看订单详情");
                            tvOrderTel.setText(order.getOrderNumber() + "");
                            tvOrderMoney.setText("¥" + order.getShouldPayTotal() + "");
                            tvUnderOrderTime.setText(order.getCreateOrderTime());
                            tvOrderWay.setText(order.getPayWayName());
                            ivPic.setImageResource(R.mipmap.ic_pay_succeed);
                            llPayFailed.setVisibility(View.GONE);
                            tvLookOrder.setVisibility(View.VISIBLE);
                            llList.setVisibility(View.VISIBLE);
                        } else if (!TextUtils.isEmpty(pay_state) && pay_state.equals("2")) {
                            tvTitle.setText("支付失败");
                            tvPaystateTitle.setText("订单支付失败，请重新支付");
                            tvOrderTel.setText(order.getOrderNumber() + "");
                            tvOrderMoney.setText("¥" + order.getShouldPayTotal() + "");
                            tvUnderOrderTime.setText(order.getCreateOrderTime());
                            tvOrderWay.setText(order.getPayWayName());
                            ivPic.setImageResource(R.mipmap.ic_pay_failed);
                            llPayFailed.setVisibility(View.VISIBLE);
                            tvLookOrder.setVisibility(View.GONE);
                            llList.setVisibility(View.GONE);
                        }

                    }
                }

                @Override
                public void errListener(String error_msg) {
                    CircleProgressDialog.closeDialog();
                    Log.e("cjx", error_msg);

                    loading_layout.setStatus(LoadingLayout.ERROR);

                }
            });

//            CircleProgressDialog.showDialog(PaySucceedActivity.this);
        } else {
            startActivity(LoginActivity.getIntent(PaySucceedActivity.this, "ddddd"));
        }

//
//            loading_layout.setOnReloadListener(new LoadingLayout.OnReloadListener() {
//                @Override
//                public void onReload(View v) {
//                    HttpManager.getInstance().doHttpDeal(payConsequencePXApi);
//                    loading_layout.setStatus(LoadingLayout.LOADING);
//                }
//
//                @Override
//                public void onReturn(View v) {
//                    onBackPressed();
//                }
//            });
//            loading_layout.setStatus(LoadingLayout.LOADING);
//        } else {
//            loading_layout.setStatus(LoadingLayout.EMPTY);
//        }
    }

    private void caiLike() {
        if (!getSharedPreferencesUtil().getLogintoken().isEmpty()) {
            Map<String, String> map = new HashMap<>();
            map.put("token", getSharedPreferencesUtil().getLogintoken());
            final CaiLikeApi caiLikeApi = new CaiLikeApi(this, simpleOnNextListenerCaiLike);
            caiLikeApi.setCache(false);
            caiLikeApi.setMap(map);
            HttpManager.getInstance().doHttpDeal(caiLikeApi);

            loading_layout.setOnReloadListener(new LoadingLayout.OnReloadListener() {
                @Override
                public void onReload(View v) {
                    HttpManager.getInstance().doHttpDeal(caiLikeApi);
                    loading_layout.setStatus(LoadingLayout.LOADING);
                }

                @Override
                public void onReturn(View v) {
                    onBackPressed();
                }
            });
            loading_layout.setStatus(LoadingLayout.LOADING);
        } else {
            loading_layout.setStatus(LoadingLayout.EMPTY);
        }

    }

    private void resultQuery() {
        if (!getSharedPreferencesUtil().getLogintoken().isEmpty()) {
            Map<String, String> map = new HashMap<>();
            map.put("orderId", order_id);
            map.put("token", getSharedPreferencesUtil().getLogintoken());
         /*   final PayConsequenceApi payConsequenceApi = new PayConsequenceApi(this, simpleOnNextListener);
            payConsequenceApi.setCache(false);
            payConsequenceApi.setMap(map);
            HttpManager.getInstance().doHttpDeal(payConsequenceApi);

            loading_layout.setOnReloadListener(new LoadingLayout.OnReloadListener() {
                @Override
                public void onReload(View v) {
                    HttpManager.getInstance().doHttpDeal(payConsequenceApi);
                    loading_layout.setStatus(LoadingLayout.LOADING);
                }

                @Override
                public void onReturn(View v) {
                    onBackPressed();
                }
            });*/
            loading_layout.setStatus(LoadingLayout.LOADING);


            SmartHttp.postHttpForm(AppUtils.BASE_URL + "pay/payConsequence", map, new NetResponseListener() {
                @Override
                public void sucListener(JSONObject response) {
                    Gson gson = new Gson();
                    ResultQuerySmartBean resultQuerySmartBean = gson.fromJson(response.toString(), ResultQuerySmartBean.class);
                    if (!resultQuerySmartBean.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                        ToastTools.showToast(PaySucceedActivity.this, resultQuerySmartBean.getMsg());
                        return;
                    }
                    loading_layout.setStatus(LoadingLayout.SUCCESS);

                    if (!resultQuerySmartBean.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                        ToastTools.showToast(PaySucceedActivity.this, resultQuerySmartBean.getMsg());
                        return;
                    }
                    loading_layout.setStatus(LoadingLayout.SUCCESS);

                    if (resultQuerySmartBean.getData() != null) {

                        ResultQuerySmartBean.DataBean data = resultQuerySmartBean.getData();
                        ResultQuerySmartBean.DataBean.OrderBean order = data.getOrder();
                        if (data.isStatus()) {
                            tvTitle.setText("支付成功");
                            tvPaystateTitle.setText("订单支付成功，您可查看订单详情");
                            tvOrderTel.setText(order.getOrderSn() + "");
                            tvOrderMoney.setText("¥" + order.getOrderAmount() + "");
                            tvUnderOrderTime.setText(data.getPayTime());
                            tvOrderWay.setText(order.getPayName());
                            ivPic.setImageResource(R.mipmap.ic_pay_succeed);
                            llPayFailed.setVisibility(View.GONE);
                            tvLookOrder.setVisibility(View.VISIBLE);
                            llList.setVisibility(View.VISIBLE);
                        } else {
                            tvTitle.setText("支付失败");
                            tvPaystateTitle.setText("订单支付失败，请重新支付");
                            tvOrderTel.setText(order.getOrderSn() + "");
                            tvOrderMoney.setText("¥" + order.getOrderAmount() + "");
                            tvUnderOrderTime.setText(data.getPayTime());
                            tvOrderWay.setText(order.getPayName());
                            ivPic.setImageResource(R.mipmap.ic_pay_failed);
                            llPayFailed.setVisibility(View.VISIBLE);
                            tvLookOrder.setVisibility(View.GONE);
                            llList.setVisibility(View.GONE);
                        }

                    }
                }

                @Override
                public void errListener(String error_msg) {
                    CircleProgressDialog.closeDialog();
                    Log.e("cjx", error_msg);

                    loading_layout.setStatus(LoadingLayout.ERROR);

                }
            });
        } else {
            loading_layout.setStatus(LoadingLayout.EMPTY);
        }
    }

    @Override
    protected void addListener() {

        tvAgainPay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (DateUtils.isFastDoubleClick())return;

                    if (order_type != 5) {
                        //标准从新下单
                        againPay();
                    } else {
                        //培训从新下单
                        againPayPX();
                    }




            }
        });
        tvLookOrderGray.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (order_type != 5) {
                    Intent intent = new Intent(context, OrderDetailsActivity.class);
                    intent.putExtra(ORDER_ID, order_id + "");

                    ((Activity) context).startActivityForResult(intent, COMMENT_FORCODE);
                } else {
                    Intent intent = new Intent(context, OrderDetailsPXActivity.class);
                    intent.putExtra(ORDER_SN, order_sn + "");

                    ((Activity) context).startActivityForResult(intent, COMMENT_FORCODE);
                }
            }
        });
        tvLookOrder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (order_type != 5) {
                    Intent intent = new Intent(context, OrderDetailsActivity.class);
                    intent.putExtra(ORDER_ID, order_id + "");

                    ((Activity) context).startActivityForResult(intent, COMMENT_FORCODE);
                } else {
                    Intent intent = new Intent(context, OrderDetailsPXActivity.class);
                    intent.putExtra(ORDER_SN, order_sn + "");

                    ((Activity) context).startActivityForResult(intent, COMMENT_FORCODE);
                }
            }
        });
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (order_type != 5) {
                    Intent intent = new Intent(context, OrderDetailsActivity.class);
                    intent.putExtra(ORDER_ID, order_id + "");

                    ((Activity) context).startActivityForResult(intent, COMMENT_FORCODE);
                } else {
                    Intent intent = new Intent(context, OrderDetailsPXActivity.class);
                    intent.putExtra(ORDER_SN, order_sn + "");

                    ((Activity) context).startActivityForResult(intent, COMMENT_FORCODE);
                }
            }
        });

    }

    private void againPayPX() {
        if (!getSharedPreferencesUtil().getLogintoken().isEmpty()) {

            Map<String, String> paramsBody = new HashMap<>();
            if (TextUtils.isEmpty(order_sn)) {
                ToastTools.showToast(context, "没有获取到订单编号");
                return;
            }
            this.order_sn = order_sn;
            this.order_type = order_type;
//            paramsBody.put("orderId", orderId+"");
            paramsBody.put("token", getSharedPreferencesUtil().getLogintoken());

            //获取支付方式
            final ToPayPXApi toPayPXApi = new ToPayPXApi(this, simpleOnNextListenerPayWayPX);
            toPayPXApi.setCache(false);
            toPayPXApi.setMap(paramsBody);
            HttpManager.getInstance().doHttpDeal(toPayPXApi);


        }
    }

    private void againPay() {
        if (!getSharedPreferencesUtil().getLogintoken().isEmpty()) {
            Map<String, String> paramsBody = new HashMap<>();

            paramsBody.put("orderId", order_id);


            paramsBody.put("token", getSharedPreferencesUtil().getLogintoken());
            //历史单位开票信息请求
            final ToPayApi toPayApi = new ToPayApi(PaySucceedActivity.this, simpleOnNextListenerPayWay);
            toPayApi.setCache(false);
            toPayApi.setMap(paramsBody);
            HttpManager.getInstance().doHttpDeal(toPayApi);

            loading_layout.setOnReloadListener(new LoadingLayout.OnReloadListener() {
                @Override
                public void onReload(View v) {
                    HttpManager.getInstance().doHttpDeal(toPayApi);
                    loading_layout.setStatus(LoadingLayout.LOADING);
                }

                @Override
                public void onReturn(View v) {
                    onBackPressed();
                }
            });
            loading_layout.setStatus(LoadingLayout.LOADING);
        } else {
            loading_layout.setStatus(LoadingLayout.EMPTY);
        }
    }


    private void selectPay(PayWayBean data) {


        View inflate = LayoutInflater.from(this).inflate(R.layout.select_pay_way_layout, null);
        RelativeLayout rl_close = (RelativeLayout) inflate.findViewById(R.id.rl_close);
//        final ImageView chat_btn = (ImageView) inflate.findViewById(R.id.chat_btn);
//        final ImageView ali_btn = (ImageView) inflate.findViewById(R.id.ali_btn);
//        final ImageView zhuanzhang_btn = (ImageView) inflate.findViewById(R.id.zhuanzhang_btn);
//        final ImageView yue_btn = (ImageView) inflate.findViewById(R.id.yue_btn);
//        final ImageView shop_pay_btn = (ImageView) inflate.findViewById(R.id.shop_pay_btn);
        RecyclerView recy_list = inflate.findViewById(R.id.recy_list);
        final ImageView iv_agree = (ImageView) inflate.findViewById(R.id.iv_agree);
        final TextView tv_submit_order = (TextView) inflate.findViewById(R.id.tv_submit_order);
        final TextView tv_pay_agreen = (TextView) inflate.findViewById(R.id.tv_pay_agreen);
        EditText et_use_yue = inflate.findViewById(R.id.et_use_yue);
        final LinearLayout ll_use_yue = (LinearLayout) inflate.findViewById(R.id.ll_use_yue);


        String orderPriceSubmit = tvOrderMoney.getText().toString();
        orderPriceSubmit = orderPriceSubmit.replace("¥", "");
        tv_submit_order.setText("确认付款 ¥" + MoneyShowUtils.dealNumber(orderPriceSubmit));
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recy_list.setLayoutManager(linearLayoutManager);
        payWayAdapter = new PayWayAdapter(this, paymentList);
        recy_list.setAdapter(payWayAdapter);
        payWayAdapter.setOrderType(order_type);

        //只有ordertype==4才有余额支付
        if (order_type == 4) {
            ll_use_yue.setVisibility(View.VISIBLE);
        } else {
            ll_use_yue.setVisibility(View.GONE);
        }

        payWayAdapter.setYueMoney(data.getUserMoney());
        payWayAdapter.setOrderPrice(orderPriceSubmit);
        payWayAdapter.notifyDataSetChanged();

        //用户支付协议应默认为勾选状态
        iv_agree.setSelected(isAgreement);
//        chat_btn.setRJCPSelected(true);
        commonPop(inflate);
        //关闭按钮
        rl_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogCustom.showDoubleDialog(PaySucceedActivity.this, "", "确认放弃付款？", "确认离开", "继续支付", new DialogCustom.CustomDialogDouble() {
                    @Override
                    public void rightButtonClicked() {

                    }

                    @Override
                    public void leftButtonClicked() {
                        if (order_type != 5) {
                            Intent intent = new Intent(context, OrderDetailsActivity.class);
                            intent.putExtra(ORDER_ID, order_id + "");

                            ((Activity) context).startActivityForResult(intent, COMMENT_FORCODE);
                        } else {
                            Intent intent = new Intent(context, OrderDetailsPXActivity.class);
                            intent.putExtra(ORDER_SN, order_id + "");

                            ((Activity) context).startActivityForResult(intent, COMMENT_FORCODE);
                        }
                        popupWindow.dismiss();
                    }
                });

            }
        });
        String finalOrderPriceSubmit = orderPriceSubmit;
        et_use_yue.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

                if (TextUtils.isEmpty(s.toString())){
                    tv_submit_order.setText("确认付款 ¥" + MoneyShowUtils.dealNumber(finalOrderPriceSubmit));
                    return;
                }
                if ((Double.parseDouble(finalOrderPriceSubmit)-Double.parseDouble(s.toString()))<0){
                    ToastTools.showToast(PaySucceedActivity.this,"使用余额的金额应不能大于付款金额");
                    et_use_yue.setText(finalOrderPriceSubmit);
                }else if ((data.getUserMoney()-Double.parseDouble(s.toString()))<0){
                    ToastTools.showToast(PaySucceedActivity.this,"使用余额的金额应不能大于所剩余额");

                }else {
                    if (payId!=-1){
                        tv_submit_order.setText("确认付款 ¥" + MoneyShowUtils.dealNumber((Double.parseDouble(finalOrderPriceSubmit)-Double.parseDouble(s.toString()))+""));
                    }
                }

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        //列表点击事件
        payWayAdapter.setOnClickItem(new PayWayAdapter.OnClickItem() {
            @Override
            public void OnClickListion(View view, int postion) {
                if (paymentList != null && paymentList.size() > 0) {
                    payId = paymentList.get(postion).getPayId();
                }
                payWayAdapter.setmSelectedPos(postion);

                if (payId == 5) {

                    String orderPriceSubmit = tvOrderMoney.getText().toString();
                    orderPriceSubmit = orderPriceSubmit.replace("¥", "");
                    et_use_yue.setText(MoneyShowUtils.dealNumber(orderPriceSubmit));

                } else {
                    et_use_yue.setText("");
                }

                payWayAdapter.notifyDataSetChanged();
            }
        });
        //支付协议
        tv_pay_agreen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(PaySucceedActivity.this, PayAgreenActivity.class);
                startActivity(intent);
            }
        });

        //同意条款
        iv_agree.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isAgreement = !isAgreement;
                iv_agree.setSelected(isAgreement);
            }
        });
        //付款提交
        tv_submit_order.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ////payId  2  微信支付   3     支付宝     4    银行汇款/转账     6   到店支付     5   余额支付
                String useYue = et_use_yue.getText().toString().trim();
                String submitMoney = tv_submit_order.getText().toString().trim();
                submitMoney = submitMoney.replace("确认付款 ¥", "");
               /* if (Double.parseDouble(submitMoney) <= 0) {
                    if (payId == 2 || payId == 3 || payId == 4 || payId == 6) {
                        ToastTools.showLongToast(PaySucceedActivity.this, "支付金额为0，请选择余额支付");
                        return;
                    }

                }*/
                if (!iv_agree.isSelected()) {
                    ToastTools.showLongToast(PaySucceedActivity.this, "同意条款才能进行支付");
                    return;
                } else if (payId != -1 && payId == 5) {
                    /*if (!TextUtils.isEmpty(useYue)) {
                        ToastTools.showLongToast(PaySucceedActivity.this, "选择余额支付后无需填写余额");
                        return;
                    } else*/ if (Double.parseDouble(submitMoney) > data.getUserMoney()) {
                        ToastTools.showLongToast(PaySucceedActivity.this, "余额不足请充值或选择其他支付方式！");
                        return;
                    }
                } else if (payId != -1 && payId != 5) {
                    String orderPriceSubmit = tvOrderMoney.getText().toString();
                    orderPriceSubmit = orderPriceSubmit.replace("¥", "");
                    if (!TextUtils.isEmpty(useYue)) {
                        if (Double.parseDouble(useYue) > Double.parseDouble(orderPriceSubmit)) {
                            ToastTools.showLongToast(PaySucceedActivity.this, "您选择了混合的支付方式，请填写正确的金额");
                            return;
                        }
                    }

                } else if (data.getUserMoney() <= 0) {
                    useYue = "0.00";
                } else if (payWayAdapter.getBalancePayId() == -1 && payId == -1) {
                    ToastTools.showLongToast(PaySucceedActivity.this, "请选择支付方式！");
                    return;
                } /*else if (payId == -1) {
                    ToastTools.showLongToast(OrderConfirmActivity.this, "请选择支付方式！");
                    return;
                }*/
                if (order_type != 5) {
                    if (payWayAdapter.getBalancePayId() == 5 || payId == 5) {
                        paySubmit(useYue);
                    } else {
                        paySubmit(useYue);
                    }

                } else {
                    if (payWayAdapter.getBalancePayId() == 5 || payId == 5) {
                        paySubmitPX(useYue);
                    } else {
                        paySubmitPX(useYue);

                    }
                }

            }
        });


    }

    private void paySubmitPX(String useYue) {

        if (!getSharedPreferencesUtil().getLogintoken().isEmpty()) {
            Map<String, String> paramsBody = new HashMap<>();
            if (TextUtils.isEmpty(order_sn)) {
                ToastTools.showToast(context, "没有获取到支付ID");
                return;
            }
            paramsBody.put("orderNumber", order_sn);
            paramsBody.put("token", getSharedPreferencesUtil().getLogintoken());

            if (payWayAdapter.getBalancePayId() == -1 && payId == -1) {
                return;
            }
            paramsBody.put("payId", payId + "");
            //支付提交
            final PaySubmitPXApi paySubmitPXApi = new PaySubmitPXApi(this, simpleOnNextListenerPaySubmitPX);
            paySubmitPXApi.setCache(false);
            paySubmitPXApi.setMap(paramsBody);
            HttpManager.getInstance().doHttpDeal(paySubmitPXApi);


        }

    }

    //培训支付提交
    HttpOnNextListener simpleOnNextListenerPaySubmitPX = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            paymentList.clear();
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }
            popupWindow.dismiss();
            if ((PayVo) subjects.getData() != null) {
                final PayVo payVo = (PayVo) subjects.getData();
                if (javaPayUtil == null) {
                    javaPayUtil = new JavaPayUtil(context, new JavaPayUtil.PaySuccessCallBack() {
                        @Override
                        public void paySuccess() {
//                            Intent intent = new Intent();
//                            setResult(MEMBER_REFRESH, intent);
//                            finish();
//                            ToastTools.showToast(OrderConfirmActivity.this,"支付成功");
//                            new Intent(OrderConfirmActivity.this,)
                            if (TextUtils.isEmpty(order_sn)) {
                                ToastTools.showToast(context, "没有获取到支付ID");
                                return;
                            }
                            pay_state = "1";
                            resultQueryPX();

                        }

                        @Override
                        public void expertPaySuccess(String consultType) {

                        }

                        @Override
                        public void payCancel() {
                            if (TextUtils.isEmpty(order_sn)) {
                                ToastTools.showToast(context, "没有获取到支付ID");
                                return;
                            }
                            pay_state = "2";
                            resultQueryPX();


                        }
                    });
                }

                //orderType用来区分是否有余额支付
                if (TextUtils.isEmpty(order_sn)) {
                    payVo.setOrderType(order_type);
                }
                String payId = payVo.getPayId();
                int payID = Integer.parseInt(payId);
                //payId  2  微信支付   3     支付宝     4    银行汇款/转账     6   到店支付     5   余额支付
                if (payID == 2) {
                    javaPayUtil.payByWay(payVo, "WeChat");
                } else if (payID == 3) {
                    javaPayUtil.payByWay(payVo, "Alipay");
                } else if (payID == 4) {
                    Intent intent = new Intent(context, BankPayActivity.class);
                    intent.putExtra("order_sn", order_sn + "");
                    intent.putExtra("orderType", order_type + "");
                    context.startActivity(intent);

                } else if (payWayAdapter.getBalancePayId() == 5 || payID == 5) {
                    if (TextUtils.isEmpty(order_sn)) {
                        ToastTools.showToast(context, "没有获取到订单ID");
                        return;
                    }
                    resultQueryPX();
                } else if (payID == 6) {
                    Intent intent = new Intent(context, ShopPayActivity.class);
                    context.startActivity(intent);
                }

            }
        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
        }
    };
    /*private void selectPay( PayWayBean data) {
        View inflate = LayoutInflater.from(this).inflate(R.layout.select_pay_way_layout, null);
        RelativeLayout rl_close = (RelativeLayout) inflate.findViewById(R.id.rl_close);
//        final ImageView chat_btn = (ImageView) inflate.findViewById(R.id.chat_btn);
//        final ImageView ali_btn = (ImageView) inflate.findViewById(R.id.ali_btn);
//        final ImageView zhuanzhang_btn = (ImageView) inflate.findViewById(R.id.zhuanzhang_btn);
//        final ImageView yue_btn = (ImageView) inflate.findViewById(R.id.yue_btn);
//        final ImageView shop_pay_btn = (ImageView) inflate.findViewById(R.id.shop_pay_btn);
        RecyclerView recy_list = inflate.findViewById(R.id.recy_list);
        final ImageView iv_agree = (ImageView) inflate.findViewById(R.id.iv_agree);
        final TextView tv_submit_order = (TextView) inflate.findViewById(R.id.tv_submit_order);
        final EditText et_use_yue = (EditText) inflate.findViewById(R.id.et_use_yue);
        //使用余额
        final String use_yue = et_use_yue.getText().toString().trim();

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recy_list.setLayoutManager(linearLayoutManager);
        payWayAdapter = new PayWayAdapter(this,paymentList);
        recy_list.setAdapter(payWayAdapter);

        String orderPrice = tvOrderMoney.getText().toString().trim();
        orderPrice = orderPrice.replace("¥", "");


        payWayAdapter.setOrderType(order_type);
        payWayAdapter.setYueMoney(data.getUserMoney());
        payWayAdapter.setOrderPrice(orderPrice);
        payWayAdapter.notifyDataSetChanged();


        iv_agree.setSelected(isAgreement);
//        chat_btn.setRJCPSelected(true);
        commonPop(inflate);
        //关闭按钮
        rl_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });

        //列表点击事件
        payWayAdapter.setOnClickItem(new PayWayAdapter.OnClickItem() {
            @Override
            public void OnClickListion(View view, int postion) {
                if (paymentList!=null&&paymentList.size()>0){
                    payId=paymentList.get(postion).getPayId();
                }
                payWayAdapter.setmSelectedPos(postion);
                payWayAdapter.notifyDataSetChanged();
            }
        });
//        chat_btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onUpTimeClick(View v) {
//                chat_btn.setRJCPSelected(true);
//                ali_btn.setRJCPSelected(false);
//                zhuanzhang_btn.setRJCPSelected(false);
//                yue_btn.setRJCPSelected(false);
//                shop_pay_btn.setRJCPSelected(false);
//                Toast.makeText(OrderConfirmActivity.this, "点击了", Toast.LENGTH_SHORT).show();
//            }
//        });
//        ali_btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onUpTimeClick(View v) {
//                chat_btn.setRJCPSelected(false);
//                ali_btn.setRJCPSelected(true);
//                zhuanzhang_btn.setRJCPSelected(false);
//                yue_btn.setRJCPSelected(false);
//                shop_pay_btn.setRJCPSelected(false);
//            }
//        });
//        zhuanzhang_btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onUpTimeClick(View v) {
//                chat_btn.setRJCPSelected(false);
//                ali_btn.setRJCPSelected(false);
//                zhuanzhang_btn.setRJCPSelected(true);
//                yue_btn.setRJCPSelected(false);
//                shop_pay_btn.setRJCPSelected(false);
//            }
//        });
//        yue_btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onUpTimeClick(View v) {
//                chat_btn.setRJCPSelected(false);
//                ali_btn.setRJCPSelected(false);
//                zhuanzhang_btn.setRJCPSelected(false);
//                yue_btn.setRJCPSelected(true);
//                shop_pay_btn.setRJCPSelected(false);
//            }
//        });
//        shop_pay_btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onUpTimeClick(View v) {
//                chat_btn.setRJCPSelected(false);
//                ali_btn.setRJCPSelected(false);
//                zhuanzhang_btn.setRJCPSelected(false);
//                yue_btn.setRJCPSelected(false);
//                shop_pay_btn.setRJCPSelected(true);
//            }
//        });
        //同意条款
        iv_agree.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isAgreement = !isAgreement;
                iv_agree.setSelected(isAgreement);
            }
        });
        //付款提交
        tv_submit_order.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                paySubmit(use_yue);
            }
        });


    }*/
//培训获取支付方式
    HttpOnNextListener simpleOnNextListenerPayWayPX = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            paymentList.clear();
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }

            PayWayBean data = (PayWayBean) subjects.getData();
            paymentList.addAll(data.getPaymentList());
            //选择支付
            selectPay(data);


        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
        }
    };

    private void commonPop(View view) {
        popupWindow = new PopupWindow(view, ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.WRAP_CONTENT, true);
        // 产生背景变暗效果
        WindowManager.LayoutParams lp = getWindow()
                .getAttributes();
        lp.alpha = 0.4f;
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        getWindow().setAttributes(lp);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.setOutsideTouchable(false);
        popupWindow.setTouchable(true);
        //从下往上弹出动画效果
        popupWindow.setAnimationStyle(R.style.bottomPopupAnimation);
        popupWindow.showAtLocation(findViewById(R.id.ll_root), Gravity.BOTTOM, 0, 0);
        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

            // 在dismiss中恢复透明度
            public void onDismiss() {
                WindowManager.LayoutParams lp = getWindow()
                        .getAttributes();
                lp.alpha = 1f;
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                getWindow().setAttributes(lp);
            }
        });
    }

    private void paySubmit(String use_yue) {
        if (!getSharedPreferencesUtil().getLogintoken().isEmpty()) {
            Map<String, String> paramsBody = new HashMap<>();
            paramsBody.put("orderId", order_id + "");
            paramsBody.put("token", getSharedPreferencesUtil().getLogintoken());

            if (payWayAdapter.getBalancePayId() == -1 && payId == -1) {
                ToastTools.showToast(PaySucceedActivity.this, "请选择支付方式");
                return;
            }
            paramsBody.put("payId", payId + "");
            if (!TextUtils.isEmpty(use_yue)) {
                paramsBody.put("balance", use_yue);
            } else {
                paramsBody.put("balance", 0 + "");
            }

            //支付提交
            final PaySubmitApi paySubmitApi = new PaySubmitApi(PaySucceedActivity.this, simpleOnNextListenerPaySubmit);
            paySubmitApi.setCache(false);
            paySubmitApi.setMap(paramsBody);
            HttpManager.getInstance().doHttpDeal(paySubmitApi);

            loading_layout.setOnReloadListener(new LoadingLayout.OnReloadListener() {
                @Override
                public void onReload(View v) {
                    HttpManager.getInstance().doHttpDeal(paySubmitApi);
                    loading_layout.setStatus(LoadingLayout.LOADING);
                }

                @Override
                public void onReturn(View v) {
                    onBackPressed();
                }
            });
            loading_layout.setStatus(LoadingLayout.LOADING);
        } else {
            loading_layout.setStatus(LoadingLayout.EMPTY);
        }
    }

    //支付提交
    HttpOnNextListener simpleOnNextListenerPaySubmit = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            paymentList.clear();
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }
            loading_layout.setStatus(LoadingLayout.SUCCESS);
            popupWindow.dismiss();
            if ((PayVo) subjects.getData() != null) {
                final PayVo payVo = (PayVo) subjects.getData();
                if (javaPayUtil == null) {
                    javaPayUtil = new JavaPayUtil(context, new JavaPayUtil.PaySuccessCallBack() {
                        @Override
                        public void paySuccess() {


                            if (order_type != 5) {
                                //查询支付结果
                                resultQuery();
                            } else {
                                //培训查询支付结果
                                resultQueryPX();
                            }
                        }

                        @Override
                        public void expertPaySuccess(String consultType) {

                        }

                        @Override
                        public void payCancel() {
                            if (order_type != 5) {
                                //查询支付结果
                                resultQuery();
                            } else {
                                //培训查询支付结果
                                resultQueryPX();
                            }
                        }
                    });
                }

                //orderType用来区分是否有余额支付
                payVo.setOrderType(order_type);
                String payId = payVo.getPayId();
                int payID = Integer.parseInt(payId);
                //payId  2  微信支付   3     支付宝     4    银行汇款/转账     6   到店支付     5   余额支付
                if (payID == 2) {
                    javaPayUtil.payByWay(payVo, "WeChat");
                } else if (payID == 3) {
                    javaPayUtil.payByWay(payVo, "Alipay");
                } else if (payID == 4) {
                    Intent intent = new Intent(context, BankPayActivity.class);
                    intent.putExtra("order_id", order_id + "");
                    intent.putExtra("order_sn", order_id + "");
                    intent.putExtra("orderType", order_type + "");
                    startActivity(intent);
                } else if (payWayAdapter.getBalancePayId() == 5 || payID == 5) {
                    if (order_type != 5) {
                        //查询支付结果
                        resultQuery();
                    } else {
                        //培训查询支付结果
                        resultQueryPX();
                    }
                } else if (payID == 6) {
                    //  enterType  1是购物车  2是商品详情
//                    if (enterType.equals("1") || enterType.equals("2")) {
                    Intent intent = new Intent(PaySucceedActivity.this, ShopPayActivity.class);
                    intent.putExtra("order_id", order_id + "");
                    intent.putExtra("order_sn", order_id + "");
                    intent.putExtra("orderType", order_type + "");
                    startActivity(intent);
                       /* finish();
                    } else {
                        Intent intent = new Intent(PaySucceedActivity.this, ShopPayActivity.class);
                        intent.putExtra("order_id", orderSubmitBean.getOrderId() + "");
                        intent.putExtra("order_sn", orderSubmitBean.getOrderNumber() + "");
                        intent.putExtra("orderType", orderType + "");
                        startActivity(intent);
                    }*/

                }

            }
        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
            if (e instanceof SocketTimeoutException || e instanceof ConnectException) {
                loading_layout.setStatus(LoadingLayout.NO_NETWORK);
            } else {
                loading_layout.setStatus(LoadingLayout.ERROR);
            }
        }
    };


    //获取支付方式
    HttpOnNextListener simpleOnNextListenerPayWay = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            paymentList.clear();
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }
            loading_layout.setStatus(LoadingLayout.SUCCESS);

            PayWayBean data = (PayWayBean) subjects.getData();
            paymentList.addAll(data.getPaymentList());
            //选择支付
            selectPay(data);


        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
            if (e instanceof SocketTimeoutException || e instanceof ConnectException) {
                loading_layout.setStatus(LoadingLayout.NO_NETWORK);
            } else {
                loading_layout.setStatus(LoadingLayout.ERROR);
            }
        }
    };

    //查询支付结果
    HttpOnNextListener simpleOnNextListener = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
//            listData.clear();
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(PaySucceedActivity.this, subjects.getMsg());
                return;
            }
            loading_layout.setStatus(LoadingLayout.SUCCESS);

            if ((ResultQueryBean) subjects.getData() != null) {

                ResultQueryBean data = (ResultQueryBean) subjects.getData();
                ResultQueryBean.OrderBean order = data.getOrder();
                if (data.isStatus()) {
                    tvTitle.setText("支付成功");
                    tvPaystateTitle.setText("订单支付成功，您可查看订单详情");
                    tvOrderTel.setText(order.getOrderSn() + "");
                    tvOrderMoney.setText("¥" + order.getOrderAmount() + "");
                    tvUnderOrderTime.setText(data.getPayTime());
                    tvOrderWay.setText(order.getPayName());
                    ivPic.setImageResource(R.mipmap.ic_pay_succeed);
                    llPayFailed.setVisibility(View.GONE);
                    tvLookOrder.setVisibility(View.VISIBLE);
                    llList.setVisibility(View.VISIBLE);
                } else {
                    tvTitle.setText("支付失败");
                    tvPaystateTitle.setText("订单支付失败，请重新支付");
                    tvOrderTel.setText(order.getOrderSn() + "");
                    tvOrderMoney.setText("¥" + order.getOrderAmount() + "");
                    tvUnderOrderTime.setText(data.getPayTime());
                    tvOrderWay.setText(order.getPayName());
                    ivPic.setImageResource(R.mipmap.ic_pay_failed);
                    llPayFailed.setVisibility(View.VISIBLE);
                    tvLookOrder.setVisibility(View.GONE);
                    llList.setVisibility(View.GONE);
                }

            }
//            listData.addAll(data);
//            historyLookListAdapter.notifyDataSetChanged();
        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
            if (e instanceof SocketTimeoutException || e instanceof ConnectException) {
                loading_layout.setStatus(LoadingLayout.NO_NETWORK);
            } else {
                loading_layout.setStatus(LoadingLayout.ERROR);
            }
        }
    };
    //培训查询支付结果
    HttpOnNextListener simpleOnNextListenerPX = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
//            listData.clear();
            CircleProgressDialog.closeDialog();
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(PaySucceedActivity.this, subjects.getMsg());
                return;
            }
            loading_layout.setStatus(LoadingLayout.SUCCESS);

            if ((ResultQueryPXBean) subjects.getData() != null) {

                ResultQueryPXBean data = (ResultQueryPXBean) subjects.getData();
                ResultQueryPXBean.OrderBean order = data.getOrder();
                if (!TextUtils.isEmpty(pay_state) && pay_state.equals("1")) {
                    tvTitle.setText("支付成功");
                    tvPaystateTitle.setText("订单支付成功，您可查看订单详情");
                    tvOrderTel.setText(order.getOrderNumber() + "");
                    tvOrderMoney.setText("¥" + order.getShouldPayTotal() + "");
                    tvUnderOrderTime.setText(order.getCreateOrderTime());
                    tvOrderWay.setText(order.getPayWayName());
                    ivPic.setImageResource(R.mipmap.ic_pay_succeed);
                    llPayFailed.setVisibility(View.GONE);
                    tvLookOrder.setVisibility(View.VISIBLE);
                    llList.setVisibility(View.VISIBLE);
                } else if (!TextUtils.isEmpty(pay_state) && pay_state.equals("2")) {
                    tvTitle.setText("支付失败");
                    tvPaystateTitle.setText("订单支付失败，请重新支付");
                    tvOrderTel.setText(order.getOrderNumber() + "");
                    tvOrderMoney.setText("¥" + order.getShouldPayTotal() + "");
                    tvUnderOrderTime.setText(order.getCreateOrderTime());
                    tvOrderWay.setText(order.getPayWayName());
                    ivPic.setImageResource(R.mipmap.ic_pay_failed);
                    llPayFailed.setVisibility(View.VISIBLE);
                    tvLookOrder.setVisibility(View.GONE);
                    llList.setVisibility(View.GONE);
                }

            }
//            listData.addAll(data);
//            historyLookListAdapter.notifyDataSetChanged();
        }


        @Override
        public void onError(final Throwable e) {
            CircleProgressDialog.closeDialog();
            Log.e("cjx", e.getMessage());
            if (e instanceof SocketTimeoutException || e instanceof ConnectException) {
                loading_layout.setStatus(LoadingLayout.NO_NETWORK);
            } else {
                loading_layout.setStatus(LoadingLayout.ERROR);
            }
        }
    };

    //猜你需要
    HttpOnNextListener simpleOnNextListenerCaiLike = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            listData.clear();
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(PaySucceedActivity.this, subjects.getMsg());
                return;
            }
            loading_layout.setStatus(LoadingLayout.SUCCESS);
            listData.addAll((ArrayList<CaiLikeBean>) subjects.getData());
            mineLikeAdapter.notifyDataSetChanged();

//            List<HistoryLookBean> data = (List<HistoryLookBean>) subjects.getData();
//            listData.addAll(data);
//            historyLookListAdapter.notifyDataSetChanged();
        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
            if (e instanceof SocketTimeoutException || e instanceof ConnectException) {
                loading_layout.setStatus(LoadingLayout.NO_NETWORK);
            } else {
                loading_layout.setStatus(LoadingLayout.ERROR);
            }
        }
    };

}
